<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>Examples</title>
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link href="" rel="stylesheet" />
</head>

<body>
    <div id="app">
        <child :nick="nickName">
            <template slot-scope="props">
                <button @click="changeName(props.newNick)">换名卡</button>
            </template>
        </child>
    </div>
    <script src="../vue.js"></script>
    <script>
        //  <!-- 需求：给页面加个按钮，改变父组件nickname的值，
            // 将其设置为牛马。要求使用作用域插槽 -->
       
        // 全局子组件
        Vue.component("child",{
             // 父传子
        props:["nick"],
            data(){
                return{
                    nickName:"牛马"
                }
            },
            template:`<div>
            <div>勇敢{{nick}},不怕困难</div>
            
            <slot :newNick="nickName"></slot>
            </div>
            `
        })
        new Vue({
            el: "#app",
            data: {
                nickName:"牛牛"
            },
            methods:{
                changeName(name){
                    this.nickName=name;
                }
            }
        })
    </script>
</body>

</html>